﻿using CodeGeneratorBootstrap.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CodeGeneratorBootstrap.Template.Web.Mapper
{
    public partial class PicklistMapper : ITemplate
    {
        public MetaData Data { get; set; }
        public List<LookupClassModel> lookups { get; set; }
        public List<PickupListModel> pickuplist { get; set; }

        //start add by kwang
        public List<PickupListModel> pickupModel;
        public int attr_id;
        public string attr_name;
        //end add by kwang

        public string Filename
        {
            get { return "{PicklistName}Mapper.cs"; }
        }

        public bool IsGenerateOneTime { get { return false; } }
        public bool IsGenerateFolder { get { return false; } }
        public bool IsRequiredOnlyOneMember { get { return true; } }
        public GenerateStyle GenerateStyle { get { return GenerateStyle.PickUp; } }

        //start add by kwang

        public void setAttributeId()
        {
            // Purpose: To get attribute id of this pickup list model (per 1 orignal pickuplist file)
            if (this.pickuplist != null)
            {
                foreach (PickupListModel item in pickuplist)
                {
                    this.attr_id = item.AttributeId;
                    this.attr_name = item.AttributeName;
                    break;
                }
            }
            else { this.attr_id = 0; }
        }

        public List<PickupListModel> setPickupList()
        {
            //Purpose : Return exactly pickup list for generate a pickup list file
            setAttributeId();
            this.pickupModel = pickuplist.FindAll(a => a.AttributeId == this.attr_id);
            if (pickuplist.Count != 0) { return pickuplist; }
            else { return null; }

        }
        //end add by kwang
    }
}
